home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / networke / xfirepow.000 / xfirepow / xfirepower-0.84 / client / input.c < prev    next >
C/C++ Source or Header  |  1995-06-15  |  4KB  |  208 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include "Wlib.h"
  4. #include "struct.h"
  5. #include "defs.h"
  6. #include "data.h"
  7. #include "proto.h"
  8.  
  9. int
  10. getcourse(ww, x, y)
  11.     W_Window ww;
  12.     int     x, y;
  13. {
  14.     double result;
  15.  
  16.     if(ww == cwin)
  17.     result = atan2((double) (x - my_dx),
  18.                (double) (my_dy - y)) / 3.14159 * 128.;
  19.     else {
  20.     x =(((map_info.m_width * GRIDWIDTH)<<4)*x)/(map_info.m_width * map_pixel);
  21.     y =(((map_info.m_height * GRIDHEIGHT)<<4)*y)/(map_info.m_height * map_pixel);
  22.     result = atan2((double) (x - me->p_x),
  23.                (double) (me->p_y - y)) / 3.14159 * 128.;
  24.     }
  25.  
  26.     return (unsigned char) (int) floor (result + 0.5);
  27. }
  28.  
  29. void do_input()
  30. {
  31.     W_Event ev;
  32.     static int oldkeys, keys=0;
  33.  
  34.     while(W_EventsPending()) {
  35.     W_NextEvent(&ev);
  36.     oldkeys = keys;
  37.     if(ev.Window == messwin[0] || 
  38.        ev.Window == messwin[1] ||
  39.        ev.Window == messwin[2] ||
  40.        ev.Window == messwin[3] ||
  41.        ev.Window == typewin)
  42.         message_event(&ev);
  43.     else if(ev.Window == optionwin)
  44.         option_event(&ev);
  45.     else {
  46.         switch(ev.type) {
  47.           case W_EV_KEY:
  48.         if(ev.Window == motdwin) {
  49.             motd_key(ev.key);
  50.         } else if(message_mode) {
  51.             message_event(&ev);
  52.         } else {
  53.             ev.key = do_keymap(ev.key);
  54.             switch(ev.key) {
  55.               case 'f'+128:
  56.             keys |= RKEY;
  57.             break;
  58.               case 'b'+128:
  59.             keys |= LKEY;
  60.             break;
  61.               case 'n'+128:
  62.             keys |= DKEY;
  63.             break;
  64.               case 'p'+128:
  65.             keys |= UKEY;
  66.             break;
  67.               case 'Q':
  68.             quit=1;
  69.             break;
  70.               case 'D':
  71.             displayoff = !displayoff;
  72.             break;
  73.               case ' ':
  74.             sendShell();
  75.             break;
  76.               case '0':
  77.               case '1':
  78.               case '2':
  79.               case '3':
  80.               case '4':
  81.               case '5':
  82.               case '6':
  83.               case '7':
  84.               case '8':
  85.               case '9':
  86.             sendSpeed(ev.key - '0');
  87.             break;
  88.               case 'b':
  89.             sendSpeed(-90);
  90.             break;
  91.               case '+':
  92.             if(udpSock < 0)
  93.                 sendUdpRequest(1);
  94.             else
  95.                 closeUdpConn();
  96.             break;
  97.               case 'M':
  98.             if(W_IsMapped(motdwin)) {
  99.                 W_DestroyWindow(motdwin);
  100.                 motdwin = 0;
  101.             } else {
  102.                 display_motd();
  103.             }
  104.             break;
  105.               case '?':
  106.             splitWindows = !splitWindows;
  107.             check_variable(&splitWindows);
  108.             break;
  109.               case 'O':
  110.             map_option_win();
  111.             break;
  112.               case 'm':
  113.             sendMine();
  114.             break;
  115.               case '\'':
  116.             start_message();
  117.             break;
  118.               case 'h': /* harvest a tree */
  119.             sendBuild(T_GRASS);
  120.             break;
  121.               case 'w':
  122.             sendBuild(T_GWALL);
  123.             break;
  124.               case 'r':
  125.             sendBuild(T_ROAD);
  126.             break;
  127.               case 'p':
  128.             sendPing();
  129.             break;
  130.               case '[':
  131.             viewHeight-=10;
  132.             printf("vh: %d, fd: %d\n", viewHeight, focalDist);
  133.             break;
  134.               case ']':
  135.             viewHeight+=10;
  136.             printf("vh: %d, fd: %d\n", viewHeight, focalDist);
  137.             break;
  138.               case '{':
  139.             focalDist-=10;
  140.             printf("vh: %d, fd: %d\n", viewHeight, focalDist);
  141.             break;
  142.               case '}':
  143.             focalDist+=10;
  144.             printf("vh: %d, fd: %d\n", viewHeight, focalDist);
  145.             break;
  146.               case 't':
  147.             if(W_IsMapped(win3d))
  148.                 W_UnmapWindow(win3d);
  149.             else
  150.                 W_MapWindow(win3d);
  151.             break;
  152.               default:
  153.             W_Beep();
  154.             break;
  155.             
  156.             }
  157.         }
  158.         break;
  159.           case W_EV_KEY_OFF:
  160.         switch(ev.key) {
  161.           case 'f'+128:
  162.             keys &= ~RKEY;
  163.             break;
  164.           case 'b'+128:
  165.             keys &= ~LKEY;
  166.             break;
  167.           case 'n'+128:
  168.             keys &= ~DKEY;
  169.             break;
  170.           case 'p'+128:
  171.             keys &= ~UKEY;
  172.             break;
  173.         }
  174.         break;
  175.           case W_EV_EXPOSE:
  176.         if(ev.Window == mapwin)
  177.             redraw_map();
  178.         else if(ev.Window == typewin)
  179.             redraw_message_win();
  180.         else if(ev.Window == playerwin)
  181.             redraw_player_win();
  182.         else if(ev.Window == motdwin)
  183.             display_motd();
  184.         else if(ev.Window == dashwin)
  185.             do_dash(1);
  186.         break;
  187.           case W_EV_BUTTON:
  188.         if(ev.Window == cwin || ev.Window == mapwin) {
  189.             if(message_mode)
  190.             end_message();
  191.             switch(ev.key) {
  192.               case W_RBUTTON:
  193.             sendCourse(getcourse(ev.Window, ev.x, ev.y));
  194.             break;
  195.               case W_LBUTTON:
  196.             sendShell();
  197.             break;
  198.             }
  199.             
  200.         }
  201.         break;
  202.         }
  203.     }
  204.     if(oldkeys != keys)
  205.         sendSteering(keys);
  206.     }
  207. }
  208.